package com.ibeeking.found.cms.api.feign.fallback;

import com.ibeeking.found.cms.api.common.dto.*;
import com.ibeeking.found.cms.api.common.dto.CampaignLowPriceDTO;
import com.ibeeking.found.cms.api.common.dto.CampaignPageDTO;
import com.ibeeking.found.cms.api.common.dto.CouponInfoDTO;
import com.ibeeking.found.cms.api.common.dto.CouponInfoPageDTO;
import com.ibeeking.found.cms.api.common.query.CampaignLowPriceFeignQuery;
import com.ibeeking.found.cms.api.common.query.CampaignPageListQuery;
import com.ibeeking.found.cms.api.common.query.CouponInfoPageQuery;
import com.ibeeking.found.cms.api.feign.CmsMarketingFeignBClient;
import com.ibeeking.nematos.utils.base.Page;
import com.ibeeking.nematos.utils.result.ResponseCodeEnum;
import com.ibeeking.nematos.utils.result.ResponseResult;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.Collections;
import java.util.List;

/**
 * 降级工场
 *
 * @Author ibeeking
 * @date 2019/1/18
 */
@Component
public class CmsMarketingBFallbackFactory implements FallbackFactory<CmsMarketingFeignBClient> {
    @Override
    public CmsMarketingFeignBClient create(Throwable throwable) {
        return new CmsMarketingFeignBClient() {

            @Override
            public ResponseResult<List<CampaignLowPriceDTO>> queryGoodsLowPrice(List<CampaignLowPriceFeignQuery> query) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "进入降级工厂，查询活动中的最低价商品规格活动信息失败。", Collections.emptyList());
            }

            @Override
            public ResponseResult<List<CouponInfoDTO>> queryInfoByIds(List<Long> ids) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "进入降级工厂，根据券ids查看券信息失败。", Collections.emptyList());
            }

            @Override
            public ResponseResult<Page<CouponInfoPageDTO>> couponPageList(CouponInfoPageQuery query) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "进入降级工厂，查询券信息失败。", null);
            }

            @Override
            public ResponseResult<Page<CampaignPageDTO>> queryCampaignPageList(CampaignPageListQuery query) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "进入降级工厂，查询活动信息失败。");
            }

        };
    }
}
